package com.ruoyi.system.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.IIndicatorService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IIndicatorSystemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-07-14
 */
@RestController
@RequestMapping("/system/system")
public class IndicatorSystemController extends BaseController
{
    @Autowired
    private IIndicatorSystemService indicatorSystemService;

    @Autowired
    private IIndicatorService indicatorService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:system:list')")
    @GetMapping("/list")
    public TableDataInfo list(IndicatorSystem indicatorSystem)
    {
        //startPage();
        List<IndicatorSystem> list = indicatorSystemService.selectIndicatorSystemList(indicatorSystem);
        return getDataTable(list);
    }

//    @PreAuthorize("@ss.hasPermi('system:system:count')")
    @GetMapping("/getCount")
    public AjaxResult getCount(){
        return success(indicatorSystemService.countIndicatorSystem());
    }


    @PreAuthorize("@ss.hasPermi('system:system:query')")
    @GetMapping("/search")
    public TableDataInfo search(QueryVo queryVo)
    {
        //startPage();
        System.out.println("HQY_DEBUG: "+queryVo);
        List<IndicatorSystem> list = indicatorSystemService.search(queryVo);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:system:indicator')")
    @GetMapping("/getIndicatorBySystemIdAndIndicatorId")
    public AjaxResult getIndicatorBySystemIdAndIndicatorId(Long systemId, Long indicatorId)
    {
        IndicatorVo vo = indicatorService.getIndicatorVoBySystemIdAndIndicatorId(systemId, indicatorId);
        return success(vo);
    }


    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:system:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IndicatorSystem indicatorSystem)
    {
        List<IndicatorSystem> list = indicatorSystemService.selectIndicatorSystemList(indicatorSystem);
        ExcelUtil<IndicatorSystem> util = new ExcelUtil<IndicatorSystem>(IndicatorSystem.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:system:info')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(indicatorSystemService.selectIndicatorSystemById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:system:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IndicatorSystemVo indicatorSystemvo)
    {
        System.out.println("HQY_DEBUG: "+indicatorSystemvo.getIndicatorWeight().size());
        return toAjax(indicatorSystemService.creatIndicatorSystem(indicatorSystemvo));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:system:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IndicatorSystem indicatorSystem)
    {
        return toAjax(indicatorSystemService.updateIndicatorSystem(indicatorSystem));
    }

    /**
     * 批量删除指标体系（后端接口已实现）
     */
    @PreAuthorize("@ss.hasPermi('system:system:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return indicatorSystemService.deleteIndicatorSystemByIds(ids)>=0 ? AjaxResult.success("删除成功！") : AjaxResult.error("删除失败！");
    }

}
